//
//  FZWelComePage.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/3/30.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class FZWelComePage: UIViewController {

    lazy var welcomePage : UIImageView  = {
      let img = UIImageView()
      img.image = UIImage(named: "ad_background")
     
      return img
    }()
    
    lazy var headImg : UIImageView  = {
        let img = UIImageView()
        
        let str = FZUserViewModel.sharedUser.useraccount?.avatar_large
        if str != nil {
            
            let urlStr : URL = URL(string: (str)!)!
            
            img.sd_setImage(with:urlStr , placeholderImage: UIImage(named: "avatar_default_big"))
        }
        img.layer.cornerRadius = 50
        img.clipsToBounds = true
        return img
    }()
    lazy var lab : UILabel = {
       let label = UILabel()
       let name = FZUserViewModel.sharedUser.useraccount?.name
        if let nam = name {
            label.text = "欢迎回来, \(nam)"
        }
       label.font = UIFont.systemFont(ofSize: 13)
       return label
    }()
    override func loadView() {
        view = welcomePage
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(headImg)
        view.addSubview(lab)
        setupUI()
    }

    func setupUI() {
        
       headImg.snp.makeConstraints { (make) in
        
          make.centerX.equalTo(self.view)
          make.top.equalTo(self.view).offset(200)
          make.size.equalTo(CGSize(width: 100 , height: 100))
        
      }
      lab.snp.makeConstraints { (make) in
        make.centerX.equalTo(self.view)
        make.top.equalTo(headImg.snp.bottom).offset(10)
    }
        
}
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        startAnimation()
    }
    func startAnimation() {
        
        lab.alpha = 0
        headImg.snp.updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }

        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: {
            
            self.view.layoutIfNeeded()
            
        }) { (_) in
            
            UIView.animate(withDuration: 1, animations: { 
                
                self.lab.alpha = 1
            }, completion: { (_) in
                
                //跳转控制器
                NotificationCenter.default.post(name:NSNotification.Name(rawValue: switchVc), object: self)
            })
        }
        
        
    }
    
}












